﻿using System;
using System.Collections.Generic;
using System.Text;
using Novell.Directory.Ldap;

namespace VOL.System.Services.System
{
    public class ValidateAD
    {
        /// <summary>
        /// 验证网域账号
        /// </summary>
        /// <param name="userName">账号</param>
        /// <param name="password">密码</param>
        /// <returns></returns>
        public string ADLogin(string userName, string password)
        {
            //获取登陆页输入的域账号、密码
           
            string _adHost = "10.100.8.210";
            string adAdminUserName = userName;
            string adAdminPassword = password;
            var _adPaths = new string[] { "OU=oec2003,DC=COM,DC=cn" };

            if ((string.IsNullOrEmpty(_adHost) || string.IsNullOrEmpty(adAdminUserName)) ||
                string.IsNullOrEmpty(adAdminPassword))
            {
                return "no";
            }
            try
            {
               var  _connection = new LdapConnection();
                _connection.Connect(_adHost, 389);
                _connection.Bind("CTRUCK\\" + adAdminUserName, adAdminPassword);//注意要有域路径"CTRUCK\\"
            }
            catch
            {
                return "no";
            }

            return "ok";
        }
    }
}
